package com.pwrd.sframe.core;

import com.pwrd.sframe.core.interfaces.Msg;

import java.util.LinkedList;

/**
 * @Auther syc.
 * @Date 2017/1/19 17:32.
 */
public abstract class Service {

    protected Port port;

    protected final LinkedList<Msg> recvMsgQ = new LinkedList<>();
//    private final ConcurrentLinkedQueue<byte[]> recvMsgQ = new ConcurrentLinkedQueue<>(); //CAS算法

    protected void recvHandler(Msg msg) {
        recvMsgQ.add(msg);
    }

    protected Service(Port port) {
        this.port = port;
    }

    public abstract Object getKey();

    public void pulse() {

        pulseOverride();
    }

    /**
     * 子类可覆盖心跳
     */
    public abstract void pulseOverride();


    public void startUp() {
        port.addService(getKey(), this);
    }

}
